package allen.ui.log;

import java.awt.BorderLayout;
import java.sql.Date;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableRowSorter;

import allen.log.LogDataCenter;

/**
 * Main log frame for log entities.
 * */
class LogFrame extends JFrame {

	private static final long serialVersionUID = 1L;

	public static LogFrame logFrame = new LogFrame();

	private TableRowSorter<LogDataCenter> tableSorter = new TableRowSorter<LogDataCenter>(
			LogDataCenter.logDataCenter);

	private JTable initJTable() {
		JTable jTable = new JTable(LogDataCenter.logDataCenter);

		jTable.setDefaultRenderer(Date.class, new LongDateRenderer());
		jTable.setDefaultRenderer(Throwable.class, new ThrowableRenderer());

		jTable.setRowSorter(tableSorter);

		return jTable;
	}

	private void init() {
		JPanel jPanel = new JPanel(new BorderLayout());

		jPanel.add(new LogSettingPanel(), BorderLayout.NORTH);
		jPanel.add(new FilterSettingPanel(tableSorter), BorderLayout.SOUTH);

		JTable jTable = initJTable();
		JScrollPane scrollPane = new JScrollPane(jTable);
		jPanel.add(scrollPane, BorderLayout.CENTER);

		this.getContentPane().add(jPanel);
	}

	private LogFrame() {
		this.setSize(LogConstant.LogWidth, LogConstant.LogHeigh);
		this.setTitle(LogConstant.Title);
		this.setVisible(false);

		init();

	}
}
